package com.lltt.study.controller;

import com.lltt.study.service.ChatAssistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class RAGController {
    @Resource
    InMemoryEmbeddingStore<TextSegment> embeddingStore;

    @Resource
    ChatAssistant chatAssistant;

    @GetMapping(value = "/rag/add")
    public String testAdd(){
        Document document = FileSystemDocumentLoader.loadDocument("E:\\Desktop\\1.txt");
        EmbeddingStoreIngestor.ingest(document,embeddingStore);
        String result = chatAssistant.chat("什么时候发货？");
        System.out.println("result = " + result);
        return result;
    }
}
